export default function queueJob() {
  const queue = new Set();

  let p = Promise.resolve();

  let isFlushing = false;

  return function (job) {

    //将job添加到任务队列

    queue.add(job);

    if (!isFlushing) {

      isFlushing = true;

      p.then(() => {

        try {

          queue.forEach(jo => jo());

        } catch (e) {
          //很重要，一定要暴露出来错误

          console.error("异常", e)

        } finally {

          //重置

          isFlushing = false;

          queue.length = 0;

        }

      })

    }

  }
}